//
//  KTVHomeTableViewCell.m
//  GoShops
//
//  Created by zcj on 15-12-6.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//

#import "KTVHomeTableViewCell.h"
#import "Grouble.h"
#import "KTVModels.h"


@interface KTVHomeTableViewCell()
@property (nonatomic,weak)UILabel* shopNameLabel;

@property (nonatomic,weak)UIImageView * xingxing;
// 价格
@property (nonatomic,weak)UILabel* priceLabel;
// 地址
@property (nonatomic,weak)UILabel* evaluation;
// 介绍本店
@property(nonatomic,weak)UILabel * introductionLable;
@end
@implementation KTVHomeTableViewCell
+(instancetype)KTVHomeTableViewCell:(UITableView *)tableView
{
    static NSString *ID = @"ktvhometable";
    KTVHomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[KTVHomeTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    // 设置不能选中,选中每反应
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;

}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.userInteractionEnabled = YES;
        [self.imageView setImage:[UIImage imageNamed:@"bg_customReview_image_default"]];
        UIView * backView = [[UIView alloc]init];
        backView.frame = CGRectMake(0, 0, ScreenWidth, 120);
        backView.backgroundColor = [UIColor clearColor];
        [self addSubview:backView];
        
        CGFloat margn = 10;
        CGFloat shopImageW = 100;
        CGRect shopImg = CGRectMake(margn, margn, shopImageW, shopImageW);
        self.imageView.frame = shopImg;
        
        NSString * nameStr = @"小样";
        CGFloat nameX = CGRectGetMaxX(shopImg) + 2*margn;
        CGSize nameH = [nameStr sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]}];
        CGFloat nameW = ScreenWidth - 80 - margn * 5;
        
        CGRect shopNameLabelRect = CGRectMake(nameX, margn, nameW, nameH.height);
        UILabel* shopNameLabel = [[UILabel alloc]initWithFrame:shopNameLabelRect];
        shopNameLabel.font = [UIFont systemFontOfSize:16];
        shopNameLabel.textColor = [UIColor blackColor];
        shopNameLabel.text = @"阳光KTV";
        [backView addSubview:shopNameLabel];
        self.shopNameLabel = shopNameLabel;
        // 星星
        CGFloat sunX = nameX;
        CGFloat sunY = margn*2 + nameH.height;
        CGFloat sunW = nameW;
        CGFloat sunH = nameH.height;
        CGRect sunRect = CGRectMake(sunX, sunY, sunW, sunH);
        //
        UIImageView * xingxing = [[UIImageView alloc]init];
        xingxing.contentMode = UIViewContentModeLeft;
        [xingxing setImage:[UIImage imageNamed:@"icon_feedCell_star_empty"]];
        xingxing.frame = CGRectZero;
        xingxing.frame = CGRectMake(sunX, sunY, xingxing.image.size.width, xingxing.image.size.height);
        
        [backView addSubview:xingxing];
        
        // 地址
        CGFloat evaluationX = nameX + 2 *margn;
        CGFloat evaluationY = sunY;
        CGFloat evaluationW = 100;
        CGFloat evaluationH = nameH.height;
        CGRect evaluationSize = CGRectMake(evaluationX, evaluationY, evaluationW, evaluationH);
        
        UILabel * evaluation = [[UILabel alloc]initWithFrame:evaluationSize];
        evaluation.textColor = [UIColor blackColor];
        evaluation.text = @"九江市";
        
        evaluation.font = [UIFont systemFontOfSize:12];
        evaluation.textAlignment = NSTextAlignmentRight;
        
        [backView addSubview:evaluation];
        self.evaluation = evaluation;
        
        // 具体的地址
        NSString * strWhTest = @"朝阳区酒仙桥路18号颐堤港4层大家分开的加快立法疯狂";
             //CGFloat addrsW =
        // 例子：美发  中关村
        CGFloat priceX = sunX;
        CGFloat priceY = CGRectGetMaxY(sunRect) + margn;
        CGFloat priceW = sunW;
        CGFloat priceH = sunH;
        CGRect priceRect = CGRectMake(priceX, priceY, priceW, priceH);
        
        UILabel * priceLabel = [[UILabel alloc]initWithFrame:priceRect];
        priceLabel.numberOfLines = 0;
        priceLabel.textColor = ZCJColor(86, 221, 188);
        priceLabel.font = [UIFont systemFontOfSize:15];
        priceLabel.textAlignment = NSTextAlignmentLeft;

        [backView addSubview:priceLabel];
        self.priceLabel = priceLabel;
        
        
        // 介绍本店
        CGFloat introductionLableX = margn;
        CGFloat introductionLableY = 110;
        CGFloat introductionLableW = ScreenWidth - 2 * margn;
        CGSize introductionLableWH = [strWhTest sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:20]}];
        CGRect introductionLableRect = CGRectMake(introductionLableX, introductionLableY, introductionLableW, introductionLableWH.height);
        
        UILabel * introductionLable = [[UILabel alloc]initWithFrame:introductionLableRect];
        introductionLable.numberOfLines = 0;
        introductionLable.font = [UIFont systemFontOfSize:10];
        introductionLable.textColor = [UIColor blackColor];
        introductionLable.textAlignment = NSTextAlignmentLeft;
        [self addSubview:introductionLable];
        self.introductionLable = introductionLable;
    }
    return self;
}
- (void)setKtvModels:(KTVModels *)ktvModels
{
    _ktvModels = ktvModels;
    // 设置名称
    if (ktvModels.brandName.length == 0) {
        self.shopNameLabel.text = @"D调音乐KTV";
    }else{
        self.shopNameLabel.text = ktvModels.brandName;
    }
    // 设置价格
    self.priceLabel.text = ktvModels.discount;
    // 设置描述
    self.introductionLable.text = ktvModels.introduction;
    // 设置地址
    self.evaluation.text = ktvModels.areaName;
    // 设置图片
    [self.imageView setImageWithURL:[NSURL URLWithString:ktvModels.brandLogo] placeholderImage:[UIImage imageNamed:@"changgezhanwei"]];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat margn = 10;
    CGFloat shopImageW = 100;
    CGRect shopImg = CGRectMake(margn, margn, shopImageW, shopImageW);
    
    self.imageView.frame = shopImg;
}
- (void)awakeFromNib
{
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
